const http = require("http");
const url = require("url");

http
  .createServer((req, res) => {
    const urlObj = url.parse(req.url, true);

    res.writeHeader(200, {
      "Content-Type": "application/json;charset=utf-8",
      //cors头
      "access-control-allow-origin": "*",
    });
    switch (urlObj.pathname) {
      case "/api/aaa":
        res.end(
          JSON.stringify({
            name: "seupyy",
            age: 100,
          })
        );
        break;
      default:
        res.end("404");
    }
  })
  .listen(5000, () => {
    console.log("server start success");
  });
